const express = require('express')
const auth = require('../middleware/auth')
const router = express.Router()

// 获取仪表板统计数据
router.get('/stats', auth, (req, res) => {
  try {
    const stats = {
      totalDevices: 156,
      onlineDevices: 142,
      totalEnergy: 2847.5,
      totalParking: 320,
      availableParking: 87,
      securityAlerts: 3,
      timestamp: new Date().toISOString()
    }
    
    res.json({
      success: true,
      data: stats
    })
  } catch (error) {
    console.error('Dashboard stats error:', error)
    res.status(500).json({
      success: false,
      error: '获取统计数据失败'
    })
  }
})

// 获取实时数据
router.get('/realtime', auth, (req, res) => {
  try {
    const realtimeData = {
      energyConsumption: Math.floor(Math.random() * 1000) + 500,
      temperature: Math.floor(Math.random() * 10) + 20,
      humidity: Math.floor(Math.random() * 20) + 40,
      airQuality: Math.floor(Math.random() * 50) + 50,
      timestamp: new Date().toISOString()
    }
    
    res.json({
      success: true,
      data: realtimeData
    })
  } catch (error) {
    console.error('Dashboard realtime error:', error)
    res.status(500).json({
      success: false,
      error: '获取实时数据失败'
    })
  }
})

module.exports = router
